package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import entity.Collection;
import entity.OyxVipLevelShow;
import oyxUtil.CollectionPageUtil;
import oyxUtil.OyxVipPageUtil;
import service.OyxCollectionMessageService;
import service.impl.OyxCollectionMessageServiceImpl;


public class OyxCollectionMessageServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");	
		OyxCollectionMessageService cms = new OyxCollectionMessageServiceImpl();
		//获取 前端 传递过来的  pageNo
				String collectionPageNo = request.getParameter("collectionPageNo");
		  		if(collectionPageNo == null || "".equals(collectionPageNo)){
		  			collectionPageNo ="1";
		  		}
				//定义默认的 pageSize
				Integer collectionPageSize = 4;
				//查询出 符合 条件的 总条数
		       Integer collectionRows = cms.getCollectionRows(1);
		     //合理化 pageNo
		       int collectionPageNoInt = Integer.parseInt(collectionPageNo);
		       
		       CollectionPageUtil<Collection> collectionPageUtil = 
		  				new CollectionPageUtil<Collection>(collectionPageNoInt,collectionPageSize,collectionRows);
      
		       //第一个参数为用户id
		       List userCollection = cms.getUserCollection(1, collectionPageUtil.getcollectionPageNo(), collectionPageUtil.getCollectionPageSize());
		       collectionPageUtil.setList(userCollection);
		       
		       request.setAttribute("collectionPageUtil", collectionPageUtil);
		       request.getRequestDispatcher("Member_Collect.jsp").forward(request, response);
		       
	
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
